package com.example.demo.his.leetcode;

import java.util.Arrays;

/**
 * @auther zzc
 * @date 2021/4/9 13:52
 */
public class 寻找重复数 {

    public static void main(String[] args) {
        int[] array = new int[]{1, 2, 3, 4, 5, 5, 6};
        System.out.println(repeatNum(array));
    }

    public static int repeatNum(int[] nums) {
        Arrays.sort(nums);
        int i = 0;
        int j = 1;
        while (i < nums.length && j < nums.length) {
            if (nums[i] == nums[j]) {
                return nums[i];
            } else {
                i++;
                j++;
            }
        }
        return 0;
    }


}
